# coding=utf-8

import web
import json
from basecontroller import basecontroller
from services.devicesmanagerservices import DevicesManagerServices


class DeviceController(basecontroller):

    def POST(self, path):
        super(DeviceController, self).POST(path)
        data = web.data()
        DevicesManagerServices.set_a_device_info(data)
        return "1"

    def GET(self, path):
        print 'monkey path', path
        if path == 'get_devices':
            devices = DevicesManagerServices.get_devices_info()
            return json.dumps(devices)
        try:
            import os
            print os.path.abspath(".")
            return open('./pages/helios/monkey/' + path).read()
        except IOError, e:
            print e.message
